package com.lincong.controller;

import com.lincong.controller.frontend.MainPageController;
import com.lincong.controller.superadmin.HeadLineOperationController;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author linchong
 * @version 1.0
 * @Date: 2022-05-11 11:10
 * @Description: DispatcherServlet$
 */
@WebServlet("/")
public class DispatcherServlet extends HttpServlet {
	//参照Spring MVC,通过DispatcherServlet来进行请求派发，进而减少Servlet数量
	//1.拦截所有请求；2.解析请求；3.派发给controller中的方法进行处理


	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		System.out.println("request path is:"+req.getServletPath());
		System.out.println("request method is:"+req.getMethod());
		if(req.getServletPath() == "/frontend/getmainpageinfo" && req.getMethod() == "GET"){
			new MainPageController().getMainPageInfo(req,resp);
		}else if(req.getServletPath() == "/superadmin/addheadline" && req.getMethod() == "POST"){
			new HeadLineOperationController().addHeadLine(req,resp);
		}
	}
}
